package huawei.nktest1;

import java.util.*;

/**
 * 考试调试
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String data = sc.nextLine();
        root=new Node(' ');
        int index=0;
        StringBuilder word=new StringBuilder();
        while (index<data.length()){
            char c = data.charAt(index);
            if(c>='a'&&c<='z' || c>='A'&&c<='Z'){
                word.append(c);
            }else {
                if(word.length()>0) {
                    add(word.toString());
                    word.setLength(0);
                }
            }
            index++;
        }
        if(word.length()>0) {
            add(word.toString());
            word.setLength(0);
        }
        String suffix=sc.nextLine();
        ArrayList<String>res = find(suffix);
        if(res.size()==0){
            System.out.println(suffix);
            return;
        }
        res.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                for(int i=0;i<o1.length()&&i<o2.length();i++){
                    int diff=o1.charAt(i)-o2.charAt(i);
                    if(diff!=0) {
                        return diff;
                    }
                }
                if(o1.length()==o2.length()){
                    return 0;
                }
                return o1.length()>o2.length()?1:-1;
            }
        });
        for (int i = 0; i < res.size(); i++) {
            if(i==0){
                System.out.print(res.get(i));
            }else {
                System.out.print(" "+res.get(i));
            }

        }
    }

    private static ArrayList<String> find(String suffix) {
        ArrayList<String> res=new ArrayList<>();
        find(suffix,root,0,res);
        return res;
    }
    private static void find(String suffix,Node node,int index,ArrayList<String> res){
        if(node==null|| index>=suffix.length()){
            return;
        }
        char c= suffix.charAt(index);
        Node child=node.children.get(c);
        if(child==null){
            return;
        }
        StringBuilder builder=new StringBuilder(suffix);
        builder.setLength(builder.length()-1);
        if(index+1==suffix.length()){
            // 添加这个节点往后的点
            addSuffix(child,builder,res);
            return;
        }
        find(suffix,child,index+1,res);
    }

    private static void addSuffix(Node child, StringBuilder builder, ArrayList<String> res) {
        if(child==null){
            return;
        }
        int len =builder.length();
        builder.append(child.c);
        if(child.end){
            res.add(builder.toString());
        }
        for(Map.Entry<Character,Node>entry: child.children.entrySet()){
            addSuffix(entry.getValue(),builder,res);
        }
        builder.setLength(len);
    }

    public static void add(String word){
        add(word,root,0);
    }
    public static void add(String word,Node node,int index){
        if(index>=word.length()|| node==null){
            return;
        }
        char c= word.charAt(index);
        Node child = node.children.get(c);
        if(child==null){
            child=new Node(c);
            node.children.put(c,child);
        }
        if(index==word.length()-1){
            child.end=true;
        }else {
            add(word,child,index+1);
        }

    }
    static Node root;
    static class Node{
        char c;
        HashMap<Character,Node> children;
        boolean end;
        public Node(char c){
            this.c=c;
            children=new HashMap<>();
        }
    }
}
